<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 

// @TODO: Get results only where they are set to active

class Inventory_model extends CI_Model
{
	protected $_table;	    
	/**
	 * Constructor
	 *
	 * @access	public
	 */
	function __construct()
	{
		parent::__construct();
		$this->load->helper('date');
	}
		
	// =============================
	// = ========== GET ========== =
	// =============================
	function count_all_items()
	{
		$this->db->select('id');
		$this->db->from('vt_item');
		//$this->db->where('status',0);
		return $this->db->count_all_results();
	}
	function get_items($offset,$page)
	{
		$return = null;
		$this->db->select('*');
		$this->db->from('vt_item');		
		$this->db->limit($offset, $page);
		$query = $this->db->get();
		$return = $query->result_array();
		return $return;
	}
	function get_list_items()
	{
		$return = null;
		$this->db->select('*');
		$this->db->from('vt_item');		
		$query = $this->db->get();
		$return = $query->result_array();
		return $return;
	}
	/*
	 * Thêm Item mới với status =0; trạng thái chưa submit
	 */
	function add_item()
	{
		$data = null;
		$this->db->set($data);
		$return = $this->db->insert('vt_item');
		return $return;
	}
	
	function get_list_import_bills()
	{
		
		return null;
	}
	function add_import_bill()
	{
		return null;
	}
	function add_export_bill()
	{
		return null;
	}
	function get_list_export_bills()
	{
		return null;
	}
	
	function get_the_item($id)
	{
		$return = null;
		$this->db->select('*');
		$this->db->from('vt_item');	
		$this->db->where('id=',$id);
		$query = $this->db->get();
		$return = $query->result_array();
		if(count($return)>0)
		{
			return $return[0];
		}
		return null;
	}
	/*
	 * Chuyển trạng thái status từ 0 tới 1
	 */
	function submitinventory($id)
	{
		$data = array
				(
					'status'=> 1
				);
		$this->db->where('id',$id);
		$return = $this->db->update('vt_item',$data);
		return $return;
	}
	function edit_item($id)
	{
		$data = null;
		$this->db->where('id',$id);
		$return = $this->db->update('vt_item',$data);
		return $return;
	}
	// --------------------------------------------------------------------

}

/* Location: ./application/models/qlsv_model.php */
